import java.io.*;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

//UPD Socket is opend

public class ServerThread extends Thread {
	static DatagramSocket gameSocket;
	byte[] buf = new byte[1024];
	static String clientParam;
	static String clientIP;
	private String done="0";

	
	public ServerThread() throws IOException{
		
		try {
			gameSocket = new DatagramSocket(6789);
			System.out.println("Connection OK");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public void run() {
		
		try {
			 DatagramPacket packet = new DatagramPacket
					 (buf, buf.length);
			 while(true)
			 {
				 
				 System.out.println("Waithing for packet");
				 gameSocket.receive(packet);
				 System.out.println("Packet Recived");
				 done="1";
				 clientParam = new String(packet.getData(),0, packet.getLength());
				 clientIP =	packet.getAddress().toString();
				 System.out.println(clientParam);
	  	   }

		} catch (IOException e) {
			// TODO Auto-generated catch block
			
		} finally
		{

		}
	}
	
	public String getValue()
	{
		return clientParam;
	}
	
	public String getIP()
	{
		return clientIP;
	}
	
	public void setDone(String done){ this.done=done;}
	
	//public boolean getDone(){return done;}
	
	public String[] getValues()
	{
		return new String[]{done,clientIP,clientParam};
	}
}
